package com.zhongjianjian.dubbo.client;

import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.net.Socket;

/**
 * @类名: com.zhongjianjian.dubbo.client
 * @作者: lgt
 * @创建时间: 2020-03-04 22:09
 * @描述:
 **/
public class TestDubboInvocation implements InvocationHandler {

    private String implClass;

    public TestDubboInvocation(String implClass) {
        this.implClass = implClass;
    }

    @Override //主要逻辑的实现
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        //创建客户端
        Socket socket = new Socket("127.0.0.1",888);
        //发送请求
        ObjectOutputStream objectOutputStream = new ObjectOutputStream(socket.getOutputStream());
        //数组的信息
        objectOutputStream.writeObject(args);
        //方法的名字
        objectOutputStream.writeUTF(method.getName());
        //实现类的名字
        objectOutputStream.writeUTF(implClass);
        //接口参数类型数组
        Class<?>[] parameterTypes = method.getParameterTypes();



        //获取接口的执行结果信息
        ObjectInputStream objectInputStream = new ObjectInputStream(socket.getInputStream());
        Object o = objectInputStream.readObject();
        return o;
    }
}
